/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InterfazAdministrarAulas.java
 *
 * Created on 27/10/2011, 09:06:59 PM
 */
package presentacion;

import Paneles.PanelGeneral;
import java.awt.BorderLayout;
import business.AulaBO;
import dominio.Aula;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;

/**
 *
 * @author VIVIANA
 */
public class InterfazAdministrarAulas extends javax.swing.JFrame {
    private AulaBO bo = new AulaBO();
    private Aula a = new Aula();
    private int ok = 0;
    private ImageIcon icono;

    /** Creates new form InterfazAdministrarAulas */
    public InterfazAdministrarAulas() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);
        icono = new ImageIcon(getClass().getResource("/Imagenes/icon.gif"));
        this.setIconImage(icono.getImage());
        iniciarListaAulas();
        b_eliminarAula.setEnabled(false);
        b_editarAula.setEnabled(false);
        b_consultaAula.setEnabled(false);
        entrada4.setEnabled(false);
        entrada3.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        b_eliminarAula = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        entrada1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        entrada2 = new javax.swing.JTextField();
        crearAula = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        b_consultaAula = new javax.swing.JButton();
        b_editarAula = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        salida1 = new javax.swing.JTextField();
        salida2 = new javax.swing.JTextField();
        salida3 = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        entrada3 = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        entrada4 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        b_consultaGeneral = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaAulas = new javax.swing.JList();
        b_limpiarLista = new javax.swing.JButton();
        b_si1 = new javax.swing.JRadioButton();
        b_no1 = new javax.swing.JRadioButton();
        b_si2 = new javax.swing.JRadioButton();
        b_no2 = new javax.swing.JRadioButton();
        etiqueta1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setTitle("Administrar Aulas");
        setResizable(false);

        jLabel1.setText("Crear un Aula");

        b_eliminarAula.setText("Eliminar Aula");
        b_eliminarAula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_eliminarAulaActionPerformed(evt);
            }
        });

        jLabel3.setText("Nombre del Aula:");

        jLabel4.setText("Capacidad del Aula:");

        crearAula.setText("Crear Aula");
        crearAula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                crearAulaActionPerformed(evt);
            }
        });

        jButton3.setText("Volver al menu");
        jButton3.setActionCommand("Volver");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel5.setText("Disponible");

        jLabel9.setText("Consultar individual de Aula");

        b_consultaAula.setText("Consultar Aula");
        b_consultaAula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_consultaAulaActionPerformed(evt);
            }
        });

        b_editarAula.setText("Editar Aula");
        b_editarAula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_editarAulaActionPerformed(evt);
            }
        });

        jLabel10.setText("Nombre del Aula:");

        jLabel11.setText("Capacidad del Aula");

        jLabel12.setText("Disponible");

        salida1.setEditable(false);

        salida2.setEditable(false);

        salida3.setEditable(false);

        jLabel14.setText("Nombre del Aula:");

        jLabel15.setText("Capacidad del Aula:");

        jLabel16.setText("Disponible");

        b_consultaGeneral.setText("Consulta general");
        b_consultaGeneral.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_consultaGeneralActionPerformed(evt);
            }
        });

        listaAulas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaAulasMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(listaAulas);

        b_limpiarLista.setText("Limpiar lista");
        b_limpiarLista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_limpiarListaActionPerformed(evt);
            }
        });

        b_si1.setText("Si");
        b_si1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_si1ActionPerformed(evt);
            }
        });

        b_no1.setText("No");
        b_no1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_no1ActionPerformed(evt);
            }
        });

        b_si2.setText("Si");
        b_si2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_si2ActionPerformed(evt);
            }
        });

        b_no2.setText("No");
        b_no2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_no2ActionPerformed(evt);
            }
        });

        etiqueta1.setText("Lista de aulas registradas en el sistema");

        jLabel2.setText("Edición de Aula");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(crearAula, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel4)
                                .addComponent(jLabel1)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(entrada2, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(entrada1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(6, 6, 6)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(b_no1)
                            .addComponent(b_si1)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(30, 30, 30)
                        .addComponent(b_consultaAula, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(salida2)
                            .addComponent(salida3)
                            .addComponent(salida1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                            .addComponent(etiqueta1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(b_consultaGeneral, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(b_eliminarAula, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_limpiarLista, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(18, 18, 18)
                        .addComponent(entrada4, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(b_si2)
                            .addComponent(b_no2)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(entrada3, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(76, 76, 76)
                        .addComponent(b_editarAula, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(38, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(257, 257, 257)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(258, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {entrada1, entrada2});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {entrada3, entrada4});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4, jLabel5});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel14, jLabel15, jLabel16});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {b_no1, b_si1});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {b_no2, b_si2});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel3)
                                .addGap(6, 6, 6))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(entrada1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(entrada2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(b_si1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(b_no1)
                        .addGap(10, 10, 10)
                        .addComponent(crearAula))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(etiqueta1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(b_consultaGeneral)
                                .addGap(18, 18, 18)
                                .addComponent(b_limpiarLista)
                                .addGap(18, 18, 18)
                                .addComponent(b_eliminarAula))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(b_consultaAula))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(salida1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(salida2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(salida3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jLabel2)
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(entrada3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(entrada4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(b_si2)
                            .addComponent(jLabel16))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(b_no2)
                        .addGap(18, 18, 18)
                        .addComponent(b_editarAula)))
                .addGap(99, 99, 99)
                .addComponent(jButton3)
                .addContainerGap(55, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {entrada3, entrada4});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void iniciarListaAulas() {
        List l = bo.consultarAulas();
        DefaultListModel modelo = new DefaultListModel();
        for (int i = 0; i < l.size(); i++) {
            modelo.addElement(l.get(i) + "");
        }
        listaAulas.setModel(modelo);
    }

    
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed


    /**
     * Este metodo primero valida que los campos necesarios para la creacion de un aula
     * no se encuentren vacios, el uso de los radio button (b_si1 y b_no1) es para manejar la disponibilidad
     * del aula se invoca al metodo crearAula de la clase AulaBO y se retroalimenta al usuario informadole si su
     * transaccion fue o no fue exitosa
     */
    private void crearAulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_crearAulaActionPerformed
        int disponible = 0;
        if (entrada1.getText().equals("") || entrada2.getText().equals("")) {
            JOptionPane.showMessageDialog(this, "Debe digitar los datos completos para crear un Aula", null, JOptionPane.ERROR_MESSAGE);
        }
        else {
            if (b_si1.isSelected() == true) {
                disponible = 1;
            }
            else if (b_no1.isSelected() == true) {
                disponible = 0;
            }
            ok = bo.crearAula(entrada1.getText(), Integer.parseInt(entrada2.getText()), disponible);
 
            if (ok == 1) {
                JOptionPane.showMessageDialog(this, "Se ha creado el aula con exito", "Creacion exitosa !!!", JOptionPane.INFORMATION_MESSAGE);
                entrada1.setText("");
                entrada2.setText("");
            }
            else {
                JOptionPane.showMessageDialog(this, "Ocurrio un error al crear el aula", "Creacion fallida", JOptionPane.ERROR_MESSAGE);
            }
        }
        b_eliminarAula.setEnabled(false);
        b_editarAula.setEnabled(false);
        b_consultaAula.setEnabled(false);
        entrada4.setEnabled(false);
        entrada3.setEnabled(false);
        iniciarListaAulas();
    }//GEN-LAST:event_crearAulaActionPerformed


    private void b_eliminarAulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_eliminarAulaActionPerformed
        if (listaAulas.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar un aula de la lista para eliminar un Aula", null, JOptionPane.ERROR_MESSAGE);
        }
        else {
            Aula aula = bo.encontrarAula(listaAulas.getSelectedValue() + "");
            if (aula != null) {
                bo.borrarAula(aula.getIdAula());
                JOptionPane.showMessageDialog(this, "Se ha eliminado el aula con exito", "Eliminacion exitosa ", JOptionPane.INFORMATION_MESSAGE);
            }
            else {
                JOptionPane.showMessageDialog(this, "Ocurrio un error al eliminar el aula", "Eliminacion fallida", JOptionPane.ERROR_MESSAGE);
            }
        }
        b_eliminarAula.setEnabled(false);
        b_editarAula.setEnabled(false);
        b_consultaAula.setEnabled(false);
        entrada4.setEnabled(false);
        entrada3.setEnabled(false);
        iniciarListaAulas();
    }//GEN-LAST:event_b_eliminarAulaActionPerformed

    private void b_consultaAulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_consultaAulaActionPerformed
        Aula aula = null;
        if (listaAulas.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar un aula de la lista para eliminar un Aula", null, JOptionPane.ERROR_MESSAGE);
        }
        else {
            aula = bo.encontrarAula(listaAulas.getSelectedValue() + "");
            if (aula != null) {
                aula = bo.encontrarAula(listaAulas.getSelectedValue() + "");
                a = bo.consultarAula(aula.getIdAula());
                salida1.setText(a.getNombreAula());
                salida2.setText(a.getCapacidadAula() + "");
                if (a.getDisponibleAula() == 1) {
                    salida3.setText("Si");
                }
                else {
                    salida3.setText("No");

                }
            }
            else {
                JOptionPane.showMessageDialog(this, "Ocurrio un error al consultar el aula", "No se encontro aula", JOptionPane.ERROR_MESSAGE);
            }
        }
        b_eliminarAula.setEnabled(false);
        b_editarAula.setEnabled(false);
        b_consultaAula.setEnabled(false);
        entrada4.setEnabled(false);
        entrada3.setEnabled(false);
        iniciarListaAulas();
    }//GEN-LAST:event_b_consultaAulaActionPerformed


    private void b_editarAulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_editarAulaActionPerformed
        int disponible = 0;
        Aula aula = null;
        if (listaAulas.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar un aula de la lista para eliminar un Aula", null, JOptionPane.ERROR_MESSAGE);
        }
        else {
            aula = bo.encontrarAula(listaAulas.getSelectedValue() + "");
            if (aula != null) {
                if (b_si2.isSelected() == true) {
                    disponible = 1;
                }
                else if (b_no2.isSelected() == true) {
                    disponible = 0;
                }

                ok = bo.actualizarAula(aula.getIdAula(), entrada3.getText(), Integer.parseInt(entrada4.getText()), disponible);
                if (ok == 1) {
                    JOptionPane.showMessageDialog(this, "Se ha Actualizado el aula con exito", "Actualizacion exitosa", JOptionPane.INFORMATION_MESSAGE);
                    entrada3.setText("");
                    entrada4.setText("");
                }
                else {
                    JOptionPane.showMessageDialog(this, "Ocurrio un error al editar el aula", "Actualizacion fallida =(", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
        b_eliminarAula.setEnabled(false);
        b_editarAula.setEnabled(false);
        b_consultaAula.setEnabled(false);
        entrada4.setEnabled(false);
        entrada3.setEnabled(false);
        iniciarListaAulas();
    }//GEN-LAST:event_b_editarAulaActionPerformed


    private void b_consultaGeneralActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_consultaGeneralActionPerformed
        List l = bo.consultarAulas();
        DefaultListModel modelo =  new DefaultListModel();
        for (int i = 0; i < l.size(); i++) {
            modelo.addElement(l.get(i) + "");
        }
        listaAulas.setModel(modelo);
    }//GEN-LAST:event_b_consultaGeneralActionPerformed


    private void listaAulasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaAulasMouseClicked
        b_editarAula.setEnabled(true);
        entrada4.setEnabled(true);
        entrada3.setEnabled(true);
        b_eliminarAula.setEnabled(true);
        b_consultaAula.setEnabled(true);
    }//GEN-LAST:event_listaAulasMouseClicked


    private void b_limpiarListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_limpiarListaActionPerformed
        DefaultListModel modelo = (DefaultListModel) listaAulas.getModel();
        modelo.clear();
        listaAulas.setModel(modelo);
    }//GEN-LAST:event_b_limpiarListaActionPerformed

    private void b_si1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_si1ActionPerformed
        if (b_si1.isSelected() == true) {
            b_no1.setEnabled(false);
        }
        else if (b_si1.isSelected() == false) {
            b_no1.setEnabled(true);
        }
    }//GEN-LAST:event_b_si1ActionPerformed


    private void b_no1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_no1ActionPerformed
        if (b_no1.isSelected() == true) {
            b_si1.setEnabled(false);
        }
        else if (b_no1.isSelected() == false) {
            b_si1.setEnabled(true);
        }
    }//GEN-LAST:event_b_no1ActionPerformed


    private void b_si2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_si2ActionPerformed
        if (b_si2.isSelected() == true) {
            b_no2.setEnabled(false);
        }
        else if (b_si2.isSelected() == false) {
            b_no2.setEnabled(true);
        }
    }//GEN-LAST:event_b_si2ActionPerformed


    private void b_no2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_no2ActionPerformed
        if (b_no2.isSelected() == true) {
            b_si2.setEnabled(false);
        }
        else if (b_no2.isSelected() == false) {
            b_si2.setEnabled(true);
        }
    }//GEN-LAST:event_b_no2ActionPerformed


    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InterfazAdministrarAulas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b_consultaAula;
    private javax.swing.JButton b_consultaGeneral;
    private javax.swing.JButton b_editarAula;
    private javax.swing.JButton b_eliminarAula;
    private javax.swing.JButton b_limpiarLista;
    private javax.swing.JRadioButton b_no1;
    private javax.swing.JRadioButton b_no2;
    private javax.swing.JRadioButton b_si1;
    private javax.swing.JRadioButton b_si2;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton crearAula;
    private javax.swing.JTextField entrada1;
    private javax.swing.JTextField entrada2;
    private javax.swing.JTextField entrada3;
    private javax.swing.JTextField entrada4;
    private javax.swing.JLabel etiqueta1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList listaAulas;
    private javax.swing.JTextField salida1;
    private javax.swing.JTextField salida2;
    private javax.swing.JTextField salida3;
    // End of variables declaration//GEN-END:variables

}
